package com.xishu.service;

import com.google.common.collect.Sets;
import com.xishu.bo.LineStatus;
import com.xishu.entity.NameAndId;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.Equator;
import org.apache.commons.collections4.Predicate;

import java.util.Collection;
import java.util.HashSet;
import java.util.stream.Collectors;

public class EqualsService {
    private static EqualsService instance = new EqualsService();

    private EqualsService() {
    }

    public static EqualsService getInstance() {
        return instance;
    }

    /**
     * 判断两个数组是否相等
     *
     * @param nameAndIdList1
     * @param nameAndIdList2
     * @return
     */
    public Boolean equals(Collection<NameAndId> nameAndIdList1, Collection<NameAndId> nameAndIdList2) {
        Sets.SetView<NameAndId> intersection = Sets.intersection(new HashSet<>(nameAndIdList1), new HashSet<>(nameAndIdList2));
        return intersection.size() == nameAndIdList1.size() && intersection.size() == nameAndIdList2.size();
    }

    /**
     * 两个集合的差
     *
     * @param nameAndIdList1
     * @param nameAndIdList2
     * @return
     */
    public Collection<NameAndId> subtract(Collection<NameAndId> nameAndIdList1, Collection<NameAndId> nameAndIdList2) {
        Sets.SetView<NameAndId> difference = Sets.difference(new HashSet<>(nameAndIdList1), new HashSet<>(nameAndIdList2));
        return difference.stream().collect(Collectors.toList());
    }

}
